home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / mcomm600.zip / ZMDOS.H < prev    next >
C/C++ Source or Header  |  1994-10-03  |  19KB  |  386 lines

  1.  
  2. /*/////////////////////////////////////////////////////////////////////
  3. //                                                                   //
  4. //  ZMDOS.H -- zmodem protocol header file                           //
  5. //                                                                   //
  6. //    Mike Dumdei, 6 Holly Lane, Texarkana TX, 75503                 //
  7. //                                                                   //
  8. //////////////////////////////////////////////////////////////////// */
  9. #ifdef __cplusplus
  10.   extern "C" {
  11. #endif
  12.  
  13. /*/////////////////////////////////////////////////////////
  14. //                                                       //
  15. //  general                                              //
  16. //                                                       //
  17. //////////////////////////////////////////////////////// */
  18. typedef unsigned char BYTE;
  19. typedef unsigned int WORD;
  20. typedef unsigned long DWORD;
  21.  
  22. /*/////////////////////////////////////////////////////////
  23. //                                                       //
  24. //  compiler specific                                    //
  25. //                                                       //
  26. //////////////////////////////////////////////////////// */
  27. #ifndef __TURBOC__
  28.   #ifndef __ZTC__
  29.     #define __MSC__
  30.   #endif
  31. #endif
  32.  
  33. #define MAX_PATH            148
  34. #define KBHIT               _bios_keybrd(1)
  35. #define KBREAD              _bios_keybrd(0)
  36. #define Upd16Crc(crc,c)     ((Crc16Tbl[(crc) >> 8]) ^ (((crc) << 8) ^ (c)))
  37.  
  38. /*--------------------------------------------+
  39. |  DOS findfirst/findnext structure           |
  40. +--------------------------------------------*/
  41. typedef struct
  42. {
  43.     char reserved[21];
  44.     char attrib;
  45.     unsigned time;
  46.     unsigned date;
  47.     long size;
  48.     char name[13];
  49. } DF;
  50.  
  51. #ifdef __TURBOC__
  52.   #if (__TURBOC__ < 0x400)
  53.     #define _A_NORMAL           0
  54.     #define _A_RDONLY           FA_RDONLY
  55.     #define _A_SUBDIR           FA_DIREC
  56.     #define _A_HIDDEN           FA_HIDDEN
  57.     #define _A_SYSTEM           FA_SYSTEM
  58.     #define _A_VOLID            FA_LABEL
  59.   #endif
  60. #endif
  61.  
  62. #ifndef _MAX_PATH
  63.  #define _MAX_PATH 148
  64. #endif
  65.  
  66. /*/////////////////////////////////////////////////////////
  67. //                                                       //
  68. //  selected definitions from Chuck Forsberg's PD zmodem //
  69. //                                                       //
  70. //////////////////////////////////////////////////////// */
  71. /*--------------------------------------------+
  72. |  limits                                     |
  73. +--------------------------------------------*/
  74. #define ZATTNLEN    32        /* max length of attention string */
  75. #define MAXPACKET 1024        /* maximum size of a packet */
  76.  
  77. /*--------------------------------------------+
  78. |  special character definitions              |
  79. +--------------------------------------------*/
  80. #define ZPAD        '*'       /* pad char - begins zmodem frames */
  81. #define ZDLE      '\x18'      /* zmodem escape - aka CAN, Ctrl-X */
  82. #define ZBIN        'A'       /* binary frame indicator (CRC-16) */
  83. #define ZHEX        'B'       /* hex frame indicator */
  84. #define ZBIN32      'C'       /* binary frame indicator (CRC-32) */
  85. #define XON       '\x11'      /* XON character */
  86.  /*++ zdle sequences ++*/
  87. #define ZCRCE       'h'       /* CRC next, frame ends, hdr packet follows */
  88. #define ZCRCG       'i'       /* CRC next, frame continues nonstop */
  89. #define ZCRCQ       'j'       /* CRC next, frame continues, ZACK expected */
  90. #define ZCRCW       'k'       /* CRC next, ZACK expected, end of frame */
  91. #define ZRUB0       'l'       /* translate to DEL '\x7f' */
  92. #define ZRUB1       'm'       /* translate to DEL '\xff' */
  93. #define GOTCRCE (ZCRCE|256)   /* ZDLE-ZCRCE received */
  94. #define GOTCRCG (ZCRCG|256)   /* ZDLE-ZCRCG received */
  95. #define GOTCRCQ (ZCRCQ|256)   /* ZDLE-ZCRCQ received */
  96. #define GOTCRCW (ZCRCW|256)   /* ZDLE-ZCRCW received */
  97. #define GOTCAN     (256)      /* got 5 ZDLEs */
  98.  
  99. /*--------------------------------------------+
  100. |  zmodem frame types                         |
  101. +--------------------------------------------*/
  102. #define ZRQINIT      0        /* request receiver init */
  103. #define ZRINIT       1        /* receiver init */
  104. #define ZSINIT       2        /* sender init sequence (optional) */
  105. #define ZACK         3        /* zmodem ACK */
  106. #define ZFILE        4        /* file name from sender */
  107. #define ZSKIP        5        /* to sender: skip this file */
  108. #define ZNAK         6        /* zmodem NAK */
  109. #define ZABORT       7        /* abort batch transfers */
  110. #define ZFIN         8        /* finish session */
  111. #define ZRPOS        9        /* resume data trans at this position */
  112. #define ZDATA       10        /* data packet(s) follow */
  113. #define ZEOF        11        /* end of file */
  114. #define ZFERR       12        /* disk I/O error detected */
  115. #define ZCRC        13        /* request for file CRC and response */
  116. #define ZCHALLENGE  14        /* receiver's challenge */
  117. #define ZCOMPL      15        /* request is complete */
  118. #define ZCAN        16        /* other end canned session with CAN*5 */
  119. #define ZFREECNT    17        /* request for free bytes on filesystem */
  120. #define ZCOMMAND    18        /* command from sending program */
  121. #define ZSTDERR     19        /* output to standard error, data follows */
  122.  
  123. /*--------------------------------------------+
  124. |  Bit Masks for ZRINIT ZF0 flags             |
  125. +--------------------------------------------*/
  126. #define CANFDX     0x01       /* receiver can send and receive true FDX */
  127. #define CANOVIO    0x02       /* receiver can receive during disk I/O */
  128. #define CANBRK     0x04       /* receiver can send a break signal */
  129. #define CANCRY     0x08       /* receiver can decrypt */
  130. #define CANLZW     0x10       /* receiver can uncompress */
  131. #define CANFC32    0x20       /* receiver can use 32 bit Frame Check */
  132. #define ESCCTL     0x40       /* receiver expects ctl chars to be escaped */
  133. #define ESC8       0x80       /* receiver expects 8th bit to be escaped */
  134.  
  135. /*--------------------------------------------+
  136. |  Bit Masks for ZSINIT ZF0 flags             |
  137. +--------------------------------------------*/
  138. #define TESCCTL    0x40       /* tx expects ctl chars to be escaped */
  139. #define TESC8      0x80       /* tx expects 8th bit to be escaped */
  140.  
  141. /*--------------------------------------------+
  142. |  Bit masks for ZFILE header flags           |
  143. +--------------------------------------------*/
  144.  /*++ ZF0 flag, conversion options ++*/
  145. #define ZCBIN        1      /* binary transfer - inhibit conversion */
  146. #define ZCNL         2      /* convert NL to local end of line convention */
  147. #define ZCRESUM      3      /* resume interrupted file transfer */
  148.  /*++ ZF1 flag, management options ++*/
  149. #define ZMSKNOLOC  0x80     /* skip file if not present at rx */
  150. #define ZMMASK     0x1f     /* mask for the choices below */
  151. #define ZMNEWL       1      /* transfer if source newer or longer */
  152. #define ZMCRC        2      /* transfer if different file CRC or length */
  153. #define ZMAPND       3      /* append contents to existing file (if any) */
  154. #define ZMCLOB       4      /* replace existing file */
  155. #define ZMNEW        5      /* transfer if source newer */
  156. #define ZMDIFF       6      /* transfer if dates or lengths different */
  157. #define ZMPROT       7      /* protect destination file */
  158.  
  159. /*--------------------------------------------+
  160. |  Error return values                        |
  161. +--------------------------------------------*/
  162. #define GARB_COUNT     (-12)    /* header not found on call to ZRecvHdr */
  163. #define LONG_PKT       (-11)    /* exceeded expected block length */
  164. #define GARBLED_PKT    (-10)    /* unexpected data/invalid ZDLE sequence */
  165. #define BAD_CRC         (-9)    /* CRC incorrect */
  166. #define TIMED_OUT       (-8)    /* timed out on character receive */
  167.  
  168. #define SYNC_ERR        (-6)    /* couldn't synchronize file positions */
  169. #define MEM_ERR         (-5)    /* memory allocation error */
  170. #define FILE_ERR        (-4)    /* DOS read/write error */
  171. #define LOST_CARRIER    (-3)    /* lost carrier */
  172. #define REM_ABORT       (-2)    /* aborted by remote */
  173. #define LCL_ABORT       (-1)    /* aborted by local operator */
  174.  
  175. /*/////////////////////////////////////////////////////////
  176. //                                                       //
  177. //  zmodem definitions specific to this implementation   //
  178. //                                                       //
  179. //////////////////////////////////////////////////////// */
  180. /*--------------------------------------------+
  181. |  zmodem message types                       |
  182. +--------------------------------------------*/
  183. #define M_RHDR      0       /* received header */
  184. #define M_SHDR      1       /* sent header */
  185. #define M_BLK0      2       /* block 0 data processed (name, size, etc.) */
  186. #define M_CLASH     3       /* file name clash occurred (use ExistOpts) */
  187. #define M_FILE      4       /* start of transfer, FilePos = 1st position */
  188. #define M_EOF       5       /* end of transfer (1 file) */
  189. #define M_DATA      6       /* sent or received file data packet */
  190. #define M_FLOW      7       /* change in XOFF or CTS flow status */
  191. #define M_IDLE      8       /* waiting for character or for tx to empty */
  192. #define M_RESET     9       /* reset to 'first file' condition */
  193.  
  194. /*--------------------------------------------+
  195. |  zmodem header (i86 byte order dependent)   |
  196. +--------------------------------------------*/
  197. typedef union
  198. {
  199.     long Data;                  /* generic reference to all bytes */
  200.     long Pos;                   /* reference as a file position value */
  201.     WORD BufSz;                 /* receiver buffer size for ZRINIT */
  202.     BYTE Flg[4];                /* reference to individual flag values */
  203. } ZHEADER;
  204. enum zhdrflag { F3, F2, F1, F0 };
  205.  
  206. /*--------------------------------------------+
  207. |  bit mapped zmodem program control flags    |
  208. +--------------------------------------------*/
  209. typedef union
  210. {
  211.     int Data;                   /* reference to all bits at once */
  212.     struct                      /* reference to individual fields */
  213.     {
  214.         unsigned ExistOpts : 3; /* 0=skip, 1=resume, 2=makedup, 3=replace,
  215.                                    4=abort transfer */
  216.         unsigned KeepTime  : 1; /* use mod time in block 0 header */
  217.         unsigned EscCtl    : 1; /* escape txd ctl chars even if not req */
  218.         unsigned IgnCarrier: 1; /* ignore absence of carrier */
  219.         unsigned EndOfFile : 1; /* end of file encountered */
  220.         unsigned Receiving : 1; /* receiving if set, sending if reset */
  221.  
  222.         unsigned KBlocks   : 2; /* 0 = default (128 if X, 1024 if Y) */
  223.                                 /* 1 = force 128, 2 = force 1024 */
  224.         unsigned G         : 1; /* 1 = "g" mode, 0 = ACK mode */
  225.         unsigned CkSum     : 1; /* 1 = checksum block check, 0 = crc */
  226.         unsigned FullPath  : 1; /* 1 = send/accept complete path */
  227.         unsigned KeepAtrib : 1; /* 1 = send/accept file attributes */
  228.         unsigned SendHid   : 1; /* 1 = send hidden files */
  229.         unsigned HideSubs  : 1; /* 1 = hide created SUBDIRs with xff or % */
  230.     } F;
  231. } TFLAGS;
  232.  
  233. /*/////////////////////////////////////////////////////////
  234. //                                                       //
  235. //  async and timer specific functions                   //
  236. //                                                       //
  237. //////////////////////////////////////////////////////// */
  238. #define RxChar()          ((--RxBytesQd < 0) ? LoadRxQueue() : *RxQPtr++)
  239. #define FlushTxBuf()      async_txflush(tPort)
  240. #define FlushRxBuf()      RxBytesQd = 0, async_rxflush(tPort)
  241. #define TxChar(c)         async_tx(tPort, (c))
  242. #define TxBlock(blk, n)   async_txblk(tPort, (blk), (n))
  243. #define RxBufEmpty()      ((RxBytesQd + async_rxcnt(tPort)) == 0)
  244. #define Delay(t)          tdelay(t)
  245.  
  246. /*/////////////////////////////////////////////////////////
  247. //                                                       //
  248. //  parse file list structure/definitions                //
  249. //                                                       //
  250. //////////////////////////////////////////////////////// */
  251. /*--------------------------------------------+
  252. |  parse file list structure                  |
  253. +--------------------------------------------*/
  254. typedef struct
  255. {
  256.     char *lptr;             /* pointer to current positon in list */
  257.     DF findstruc;           /* dos findfirst/findnext structure */
  258.     char findatrib;         /* search attribute */
  259.     int flags;              /* control flags for ParseFileList function */
  260. } FILELIST;
  261.  
  262. /*--------------------------------------------+
  263. |  parse file list definitions                |
  264. +--------------------------------------------*/
  265. #define F_NOFILE      0     /* no matching files */
  266. #define F_RDWRITE     1     /* found file, has r/w attribute */
  267. #define F_RDONLY      2     /* found file, has read only attribute */
  268. #define F_SUBDIR      3     /* found subdirectory */
  269. #define F_SYSTEM      4     /* found system or volid type file */
  270. #define F_NOWILD    0x01    /* error if list contains wild cards */
  271. #define F_NOLIST    0x02    /* error if list contains multiple names */
  272. #define F_NOSYS     0x04    /* don't find subdir, hidden, system, or volid */
  273. #define F_UNIQUE    0x08    /* return duplicate name if file exists */
  274. #define F_SLASH     0x10    /* separate pathnames with forward slashes */
  275. #define F_LOWER     0x20    /* return lower case filename */
  276. #define F_FIRST     0x40    /* NZ flag value if no other options used */
  277.  
  278. /*/////////////////////////////////////////////////////////
  279. //                                                       //
  280. //  global variables                                     //
  281. //                                                       //
  282. //////////////////////////////////////////////////////// */
  283. /*--------------------------------------------+
  284. |  initialized global variables               |
  285. +--------------------------------------------*/
  286. extern char *DfltPath;          /* default download path */
  287. extern long ConnectBaud;        /* set to connect rate if using fixed link */
  288. extern int RxTimeOut;           /* receive char timeout in ticks (1/18 s.) */
  289. extern int DefRxTimeOut;        /* default value for RxTimeOut */
  290. extern int XonTimeOut;          /* max ticks before sending XON for RxChar */
  291. extern int XoffTimeOut;         /* max ticks before override for rx'd XOFF */
  292. extern int TxWindow;            /* max chars in transit, 0 if unlimited */
  293. extern int VBufSize;            /* size of variable disk buffer to use */
  294. extern TFLAGS TFlag;            /* transfer flags (resume,keeptime,ign car) */
  295. extern WORD Crc16Tbl[256];      /* 16 bit CRC table */
  296. extern BYTE ZTable[256];        /* used to speed up ZRxChar & ZTxChar */
  297.  
  298.  /*++ zrinit local receive buffer size, capability flags ++*/
  299. extern WORD BufSize;            /* 0 if overlaying I/O, else <= VBufSize */
  300. extern BYTE ZFR0;
  301. extern BYTE ZFR1;
  302.  
  303.  /*++ zsinit flags ++*/
  304. extern BYTE ZFS0;               /* don't need control characters esc'd */
  305.  
  306.  /*++ zfile management flags ++*/
  307. extern ZHEADER ZFMgt;               /* not requesting any file management */
  308. extern ZHEADER ZFMgtMask;           /* mask for incoming file mgt requests */
  309.  
  310. /*--------------------------------------------+
  311. |  uninitialized global variables             |
  312. +--------------------------------------------*/
  313. extern ASYNC *tPort;            /* pointer to port structure */
  314. extern char *PathName;          /* full pathname of current file */
  315. extern char *NameExt;           /* name and extension only of current file */
  316. extern long FilePos;            /* current file offset */
  317. extern long FileSize;           /* length of current file */
  318. extern long RxdFileSize;        /* file size from block 0 information */
  319. extern DWORD UnixTime;          /* current file time in Unix format */
  320. extern DWORD RxdUnixTime;       /* file time from block 0 information */
  321. extern WORD DosTime, DosDate;   /* current file time in DOS format */
  322. extern WORD DosAtrib;           /* file attribute of current file */
  323. extern long TotalBytes;         /* total bytes for all files */
  324. extern int TotalFiles;          /* total number of files */
  325. extern WORD SerNbr;             /* serial number of remote program */
  326. extern int BinHdr;              /* ZBIN32 if using CRC32, ZBIN if CRC16 */
  327. extern char rData32;            /* use 32 bit CRC for rx'd data packets */
  328. extern char tData32;            /* use 32 bit CRC for tx'd data packets */
  329. extern int BlkLen;              /* current block length */
  330. extern ZHEADER ZFOpts;          /* option flags received in last ZFILE hdr */
  331. extern ZHEADER ZHdr;            /* I/O buf for zmodem header data */
  332. extern WORD ErrCnt;             /* number of errors on current file */
  333. extern int BytesRxd;            /* # bytes in last data packet received */
  334. extern BYTE *IOBuf;             /* I/O buffer */
  335. extern BYTE RxQueue[128];       /* receive queue */
  336. extern BYTE *RxQPtr;            /* pointer to current RxQueue position */
  337. extern int RxBytesQd;           /* bytes in receive queue */
  338.  
  339. /*/////////////////////////////////////////////////////////
  340. //                                                       //
  341. //  function declarations                                //
  342. //                                                       //
  343. //////////////////////////////////////////////////////// */
  344. void   _C_ AsyncMode(int mode);
  345. WORD   _C_ Blk16Crc(BYTE *block, int bytes);
  346. int    _C_ BuildYZBlk0(void);
  347. void   _C_ CloseFile(void);
  348. int    _C_ DosFindFirst(char *pathname, int atrib, DF *fstruc);
  349. int    _C_ DosFindNext(DF *fstruc);
  350. long   _C_ DosGetDiskFree(int drive);
  351. int    _C_ DosSetFileTime(int handle, unsigned date, unsigned time);
  352. int    _C_ DosSetFileAttr(char *path, unsigned attrib);
  353. void   _C_ FlushDisk(void);
  354. char * _C_ GetNameExt(char *FullPath);
  355. int    _C_ GetTotalFiles(char *list, int flags);
  356. int    _C_ LoadRxQueue(void);
  357. int    _C_ OpenFile(char *name, char *mode);
  358. int    _C_ ParseFileList(FILELIST *f, int flags, ...);
  359. void   _C_ ParseYZBlk0(char *blk0);
  360. int    _C_ ReadDisk(int bytes);
  361. int    _C_ Seek(long pos);
  362. void   _C_ SendBreak(void);
  363. char * _C_ SkipChars(char *str);
  364. char * _C_ SkipSpaces(char *str);
  365. char * _C_ SwapChars(char *str, char find, char replace);
  366. int    _C_ WaitTxLevel(int level);
  367. int    _C_ WriteDisk(int bytes);
  368. int    _C_ XYInitVars(ASYNC *comport);
  369.  
  370. DWORD  _C_ DosToUnix(WORD time, WORD date);
  371. void   _C_ UnixToDos(WORD *time, WORD *date, DWORD unixtime);
  372.  
  373. DWORD  _C_ ulmul(DWORD n1, DWORD n2);
  374. DWORD  _C_ uldiv(DWORD n1, DWORD n2);
  375. DWORD  _C_ ulmod(DWORD n1, DWORD n2);
  376. DWORD  _C_ ulshl(DWORD n1, int shiftval);
  377.  
  378. int    _C_ ZmodemRecv(ASYNC *comport);
  379. int    _C_ ZmodemSend(ASYNC *comport, char *files);
  380. void   _C_ ZMsg(int type, ...);
  381.  
  382. #ifdef __cplusplus
  383.   }
  384. #endif
  385.  
  386.